/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Jun 6, 2012  4:57:31 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.construction.goods.receipted
 * File Name : GoodsReceivedProcessing.java
 * TODO
 */
package apps.business.process.construction.goods.receipted;

import java.util.List;

import jpa.entitys.synchro.staging.MmGoodsreceiptOutb;

import org.apache.log4j.Logger;

import promis.utility.CommonService;

import sap.business.mm.outbound.SyncGoodsReceiptService;

import apps.business.process.SyncProcessorCommons;
import apps.promis.out.construction.VwSyncGrnItemAction;

/**
 * @author chatree
 *
 */
public class GoodsReceivedProcessing extends SyncProcessorCommons {
	
	private static final Logger log = Logger.getLogger(GoodsReceivedProcessing.class);

	public GoodsReceivedProcessing() {
		// TODO Auto-generated constructor stub
	}
	
	public void Processing(String company, String project, String documentNo, String status, String syncIsstaging) throws Exception {
		try{
						
			UPD_PROMISUseTime(true, false, null);
			List<MmGoodsreceiptOutb> value_list = new VwSyncGrnItemAction().CreateToStaging(company, project, documentNo, status, syncIsstaging);
			System.out.println("Create to PROMIS. size=" + CommonService.getSize(value_list));
			UPD_PROMISUseTime(false, true, null);
			
			if(CommonService.getSize(value_list) > 0){
				UPD_SENDUseTime(true, false, value_list.get(0).getInstanceNo());
				new SyncGoodsReceiptService().SendToSAP(value_list);				
				UPD_SENDUseTime(false, true, value_list.get(0).getInstanceNo());
			}
			System.out.println("Send to SAP. size=" + CommonService.getSize(value_list));
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}
	
	@Deprecated
	private void Start() throws Exception {
		try{
			String company = "SP";
			String project = "SPLVILLE-PRAGSA";
			String documentNo = "76-1206-000011";
			String status = "A";
			String syncIsstaging = "N";
			
			List<MmGoodsreceiptOutb> value_list = new VwSyncGrnItemAction().CreateToStaging(company, project, documentNo, status, syncIsstaging);
			log.info(" Create to PROMIS. ");
			
			new SyncGoodsReceiptService().SendToSAP(value_list);
			log.info(" Send to SAP. ");
			
			
		}catch(Exception e){
			e.printStackTrace();
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}

//	/**
//	 * @param args
//	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		
//		try{
//			
//			new GoodsReceivedProcessing().Start();
//			
//		}catch(Exception e){
//			e.printStackTrace();
//		}
//	}

}
